#include <string>
#include <algorithm>
#include <iostream>

using namespace std;

class Solution
{
public:
    string reverseWords(string s)
    {
        auto begin = s.begin();
        auto end = s.begin();
        while (*end != '\0')
        {
            end++;
            while (*end != '\0' && *end != ' ')
            {
                end++;
            }
            reverse(begin, end);
            begin = end + 1;
        }
        return s;
    }
};
